﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;
using order.Models;

namespace order.DbConfig;

public partial class AppDbContext : DbContext
{
    public AppDbContext()
    {
    }

    public AppDbContext(DbContextOptions<AppDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<SysPermission> SysPermissions { get; set; }

    public virtual DbSet<SysRole> SysRoles { get; set; }

    public virtual DbSet<SysRolePermission> SysRolePermissions { get; set; }

    public virtual DbSet<SysUser> SysUsers { get; set; }

    public virtual DbSet<SysUserRole> SysUserRoles { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseMySql("server=192.168.27.128;user id=root;password=admin123;database=admin", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.42-mysql"));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_general_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<SysPermission>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_permission");

            entity.Property(e => e.Id)
                .HasComment("主键")
                .HasColumnType("int(11)")
                .HasColumnName("id");
            entity.Property(e => e.Permission)
                .HasMaxLength(255)
                .HasComment("资源名")
                .HasColumnName("permission");
            entity.Property(e => e.Pid)
                .HasComment("父ID")
                .HasColumnType("int(11)")
                .HasColumnName("pid");
            entity.Property(e => e.Ptype)
                .HasComment("资源类型")
                .HasColumnType("int(11)")
                .HasColumnName("ptype");
        });

        modelBuilder.Entity<SysRole>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_role");

            entity.Property(e => e.Id)
                .HasComment("角色主键")
                .HasColumnType("bigint(20)")
                .HasColumnName("id");
            entity.Property(e => e.RoleName)
                .HasMaxLength(150)
                .HasComment("角色名")
                .HasColumnName("role_name");
        });

        modelBuilder.Entity<SysRolePermission>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_role_permission");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("主键")
                .HasColumnType("int(11)")
                .HasColumnName("id");
            entity.Property(e => e.PermissionId)
                .HasComment("资源ID")
                .HasColumnType("int(11)")
                .HasColumnName("permission_id");
            entity.Property(e => e.RoleId)
                .HasComment("角色ID")
                .HasColumnType("int(11)")
                .HasColumnName("role_id");
        });

        modelBuilder.Entity<SysUser>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_user");

            entity.Property(e => e.Id)
                .HasComment("主键")
                .HasColumnType("int(11)")
                .HasColumnName("id");
            entity.Property(e => e.Email)
                .HasMaxLength(100)
                .HasColumnName("email");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

        modelBuilder.Entity<SysUserRole>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_user_role");

            entity.Property(e => e.Id)
                .HasComment("主键")
                .HasColumnType("int(11)")
                .HasColumnName("id");
            entity.Property(e => e.RoleId)
                .HasComment("角色id")
                .HasColumnType("int(11)")
                .HasColumnName("role_id");
            entity.Property(e => e.UserId)
                .HasComment("用户id")
                .HasColumnType("int(11)")
                .HasColumnName("user_id");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
